{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "cannot import name 'pywrapinit' from 'ortools.init' (d:\\anaconda\\envs\\schedule\\lib\\site-packages\\ortools\\init\\__init__.py)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mortools\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mlinear_solver\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pywraplp\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mortools\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01minit\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pywrapinit\n\u001b[0;32m      5\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmain\u001b[39m():\n\u001b[0;32m      6\u001b[0m     \u001b[38;5;66;03m# Create the linear solver with the GLOP backend.\u001b[39;00m\n\u001b[0;32m      7\u001b[0m     solver \u001b[38;5;241m=\u001b[39m pywraplp\u001b[38;5;241m.\u001b[39mSolver\u001b[38;5;241m.\u001b[39mCreateSolver(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mGLOP\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "\u001b[1;31mImportError\u001b[0m: cannot import name 'pywrapinit' from 'ortools.init' (d:\\anaconda\\envs\\schedule\\lib\\site-packages\\ortools\\init\\__init__.py)"
     ]
    }
   ],
   "source": [
    "from ortools.linear_solver import pywraplp\n",
    "from ortools.init import pywrapinit\n",
    "\n",
    "\n",
    "def main():\n",
    "    # Create the linear solver with the GLOP backend.\n",
    "    solver = pywraplp.Solver.CreateSolver('GLOP')\n",
    "    if not solver:\n",
    "        return\n",
    "\n",
    "    # Create the variables x and y.\n",
    "    x = solver.NumVar(0, 1, 'x')\n",
    "    y = solver.NumVar(0, 2, 'y')\n",
    "\n",
    "    print('Number of variables =', solver.NumVariables())\n",
    "\n",
    "    # Create a linear constraint, 0 <= x + y <= 2.\n",
    "    ct = solver.Constraint(0, 2, 'ct')\n",
    "    ct.SetCoefficient(x, 1)\n",
    "    ct.SetCoefficient(y, 1)\n",
    "\n",
    "    print('Number of constraints =', solver.NumConstraints())\n",
    "\n",
    "    # Create the objective function, 3 * x + y.\n",
    "    objective = solver.Objective()\n",
    "    objective.SetCoefficient(x, 3)\n",
    "    objective.SetCoefficient(y, 1)\n",
    "    objective.SetMaximization()\n",
    "\n",
    "    solver.Solve()\n",
    "\n",
    "    print('Solution:')\n",
    "    print('Objective value =', objective.Value())\n",
    "    print('x =', x.solution_value())\n",
    "    print('y =', y.solution_value())\n",
    "\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    pywrapinit.CppBridge.InitLogging('basic_example.py')\n",
    "    cpp_flags = pywrapinit.CppFlags()\n",
    "    cpp_flags.logtostderr = True\n",
    "    cpp_flags.log_prefix = False\n",
    "    pywrapinit.CppBridge.SetFlags(cpp_flags)\n",
    "\n",
    "    main()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "schedule",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
